package eg9_11;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class EditWindow extends JFrame implements ActionListener {
    private JMenuBar menuBar;
    private JMenu menu;
    private JSplitPane splitPane;
    private JMenuItem itemCopy,itemCut,itemPaste;
    private  JTextArea text;

    EditWindow() {
        init();
        setBounds(150, 160, 280, 290);
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
        private void init() {
            menuBar = new JMenuBar();
            menu = new JMenu("编辑");
            itemCopy = new JMenuItem("复制");
            itemCut = new JMenuItem("剪切");
            itemPaste = new JMenuItem("粘贴");
            menu.add(itemCopy);
            menu.add(itemCopy);
            menu.add(itemPaste);
            text = new JTextArea();
            add(new JScrollPane(text),BorderLayout.CENTER);
            itemCopy.addActionListener(this);
            itemCut.addActionListener(this);
            itemPaste.addActionListener(this);
        }
        public  void actionPerformed(ActionEvent e){
            if (e.getSource()==itemCopy)
                text.copy();
            else if (e.getSource()==itemCut)
                text.cut();
            else if (e.getSource()==itemPaste)
                text.paste();
        }
    }


